package de.ars.client.camera;


import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Item;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;
import javax.microedition.media.control.GUIControl;
import javax.microedition.media.control.VideoControl;

public class picture {
	
	int avaWidth=89;
	int avaHeight=111;
	static VideoControl vidc;
	static byte[] shotByteArray;
	static Player camPlayer;
	Image shot;
	
	public static VideoControl showCamera() {
		try {
			camPlayer = Manager.createPlayer("capture://video");
			camPlayer.realize();
			vidc = (VideoControl)camPlayer.getControl("VideoControl");
			return vidc;
		}
		catch (Exception e) {}
		return null;
	}
	
	public static void doSnapshot() {
		new Thread() {
			public void run() {
				try { 
					shotByteArray = vidc.getSnapshot(null);
					System.out.println("Running");
					if (shotByteArray != null) {
						Image shotImage = Image.createImage(shotByteArray, 0, shotByteArray.length); // append to form
						byte [] pngByteArray = imageProcessor.toPNG(shotImage, false); // save to PNG
						//Image snapshot = resizeImage(Image.createImage(pngByteArray, 0, pngByteArray.length),89,111);		
						Form capturedForm = new Form("Captured");
				        capturedForm.append(shotImage);
					}
				} 
				catch (Exception me) {
					me.printStackTrace();
				}
			}
		}.start();
	}
}